//
//  YMMineTabListItemView.swift
//  YMMedical
//
//  Created by y s on 2023/7/25.
//

import UIKit

class YMMineTabListItemView: UIView {

    lazy var imgvIcon: UIImageView = {
        let result = UIImageView()
        return result
    }()
    lazy var lblTitle: UILabel = {
        let result = SThemeUtil.boldLabel("", color: STheme.H_D1, fontSize: 16)
        return result
    }()
    lazy var imgvArrow: UIImageView = {
        let result = UIImageView()
        result.image = UIImage(named: "tools_list_more_arrow")
        return result
    }()
    
    var dictMain: Dictionary<String, Any>?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUI()
    }
    
    //MARK: -- UI
    func setUI() {
        backgroundColor = STheme.D9;
        clipsToBounds = true
        layer.cornerRadius = SFitUtil.fit(8)
        addSubview(imgvIcon)
        addSubview(lblTitle)
        addSubview(imgvArrow)
        
        imgvIcon.snp.makeConstraints { make in
            make.left.equalTo(SFitUtil.fit(15))
            make.size.equalTo(SFitUtil.fitSize(24, height: 24))
            make.centerY.equalToSuperview()
        }
        lblTitle.snp.makeConstraints { make in
            make.left.equalTo(imgvIcon.snp.right).offset(SFitUtil.fit(12))
            make.centerY.equalToSuperview()
            make.right.equalTo(imgvArrow.snp.left).offset(SFitUtil.fit(-12))
        }
        imgvArrow.snp.makeConstraints { make in
            make.right.equalTo(SFitUtil.fit(-15))
            make.centerY.equalToSuperview()
            make.size.equalTo(SFitUtil.fitSize(24, height: 24))
        }
        
        self.isUserInteractionEnabled = true
        
        let tap = UITapGestureRecognizer(target: self, action: #selector(tapClickAction))
        addGestureRecognizer(tap)

    }
    
    func changeData(_ dict: Dictionary<String, Any>){
        dictMain = dict
        lblTitle.text = SDataUtil.stringOf(dict["title"])
        imgvIcon.image = UIImage(named: SDataUtil.stringOf(dict["icon"]))
    }
    
    @objc func tapClickAction(){
        if dictMain != nil {
            let type = SDataUtil.intOf(dictMain!["type"])
            if type == 1 {
                //我的设备
                YMBridging.goToMyDeviceViewController()
            }else if type == 2 {
                //操作手册
                YMBridging.goToProductSpecificationVC()
            }else if type == 3 {
                //被测人管理
                YMBridging.goToTestUserVC()
            }else if type == 4 {
                //常见问题
                YMBridging.goToProblemViewController()
            }else if type == 5 {
                //意见反馈
                YMBridging.goToFeedBackVC()
            }else if type == 6 {
                //联系客服
                let urlStr = "https://107950.kefu.easemob.com/webim/im.html?configId=fecca3a7-4435-40cc-bd56-ab25d6e8c023&language=zh-CN"
                YMBridging.go(toWebVC: urlStr, title: YMBridging.kLanguage("online_server_txt"), navBarHidden: false)
            }
        }
    }
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
